local skel = fk.CreateSkill {
  name = "emo__qingsun",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__qingsun"] = "轻隼",
  [":emo__qingsun"] = "锁定技，若你本回合获得过【闪】，其他角色的【闪】对你可见；每回合结束时，若你本回合失去过【闪】，你可弃置一名角色区域内一张牌。",

  ["#emo__qingsun-throw"] = "轻隼：请选择一名角色，弃置其区域内一张牌",
  ["@@emo__qingsun-turn"] = "轻隼",
}

skel:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "jink" and info.fromArea == Player.Hand then
              return true
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn) > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return not p:isAllNude() end)
    if #targets == 0 then return false end
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#emo__qingsun-throw",
    })
    if #tos > 0 then
      local to = tos[1]
      local cid = room:askToChooseCard(player, {target = to, flag = "hej", skill_name = skel.name })
      room:throwCard(cid, skel.name, to, player)
    end
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:getMark("@@emo__qingsun-turn") == 0 and player:hasSkill(skel.name, true) then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).name == "jink" then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__qingsun-turn", 1)
  end,
})

skel:addEffect("visibility", {
  card_visible = function (self, player, card)
    if player:getMark("@@emo__qingsun-turn") ~= 0 and player:hasSkill(skel.name) then
      if card.trueName == "jink" and Fk:currentRoom():getCardArea(card.id) == Player.Hand then
        return true
      end
    end
  end,
})

return skel
